package com.huamao.niceman.scrollviewpager.information.adapter;


import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.huamao.niceman.scrollviewpager.R;
import com.huamao.niceman.scrollviewpager.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LuanXianSheng on 2017/3/3.
 * 轮播资源适配器
 */

public class ViewFlowAdapter extends BaseAdapter {
    private BaseActivity act ;
    private List<String> data  ;
    public ViewFlowAdapter(BaseActivity act){
        this.act = act ;
        data = new ArrayList<>() ;
        for (int i = 0;i<5;i++){
            data.add("http://img0.imgtn.bdimg.com/it/u=36133077,2608128411&fm=23&gp=0.jpg");
            data.add("http://img2.imgtn.bdimg.com/it/u=3204604383,1106469057&fm=23&gp=0.jpg");
            data.add("http://img1.imgtn.bdimg.com/it/u=1279286514,2871015265&fm=23&gp=0.jpg");
            data.add("http://img5.imgtn.bdimg.com/it/u=1132577205,1463157842&fm=23&gp=0.jpg");
            data.add("http://img2.imgtn.bdimg.com/it/u=336415021,1794806209&fm=23&gp=0.jpg");
        }
    }
    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {
        ViewHolder vh = null ;
        if (v == null){
            vh = new ViewHolder() ;
            v = act.getLayoutInflater().inflate(R.layout.viewfolw_image,null) ;
            vh.iv = (ImageView) v.findViewById(R.id.viewflow_img) ;
            v.setTag(vh);
        }else {
         vh = (ViewHolder) v.getTag() ;
        }
        Glide.with(act)
        .load(data.get(position%data.size()))
        .error(R.drawable.faile)
        .fallback(R.drawable.ku)
        .into(vh.iv);
        return v;
    }
    class ViewHolder{
        ImageView iv ;
    }
}
